package com.haierCamera.customapplication.ui.login;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import androidx.databinding.DataBindingUtil;

import com.haierCamera.customapplication.BaseActivity;
import com.haierCamera.customapplication.Constants;
import com.haierCamera.customapplication.R;
import com.haierCamera.customapplication.databinding.HzklActivityAdBinding;
import com.haierCamera.customapplication.ui.MainActivity;
import com.haierCamera.customapplication.utils.SharedPreferencesUtils;
import com.haierCamera.customapplication.utils.android.SystemUIHelper;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by AdministratorZJ
 * on 2019/4/2.
 *
 * @author AdministratorZJ
 */
public class HZKLAdActivity extends BaseActivity {
    private HzklActivityAdBinding welcomeBinding;
    private Timer timer = new Timer();
    private int time = 5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SystemUIHelper.setFullWindowNew(getWindow());
        welcomeBinding = DataBindingUtil.setContentView(this, R.layout.hzkl_activity_ad);
        initData();
        initView();
    }

    public void initView() {
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                time--;
                runOnUiThread(() -> {
                    welcomeBinding.timeWe.setText(String.format("%ds", time));
                    if (time == 0) {
                        timer.purge();
                        timer.cancel();
                        /*String token = SharedPreferencesUtils.getString(WelcomeActivity.this, Constants.USER_TOKEN, "");
                        if (TextUtils.isEmpty(token)) {
                            startActivity(new Intent(ct, LoginActivity.class));
                        } else {
                            startActivity(new Intent(ct, BleActivity.class));
                        }*/
                        String splash = SharedPreferencesUtils.getString(Constants.SPLASH, "");
                        if (TextUtils.isEmpty(splash)) {
                            startActivity(new Intent(HZKLAdActivity.this, HZKLSplashActivity.class));
                            finish();
                            return;
                        }
                        /*String user = SharedPreferencesUtils.getString(Constants.SP_USER_TOKEN, null);
                        Timber.i("user=%s", user);
                        if (TextUtils.isEmpty(user)) {
                            startActivity(new Intent(HZKLAdActivity.this, HZKLLoginActivity.class));
                        } else {
                            startActivity(new Intent(HZKLAdActivity.this, MainActivity.class));
                        }*/
                        startActivity(new Intent(HZKLAdActivity.this, MainActivity.class));
                        finish();
                    }
                });
            }
        }, 1000, 1000);
    }

    public void initData() {
       /* String url = getIntent().getStringExtra("url");
        GlideApp.with(this).load(url).centerCrop().into(welcomeBinding.flashIv);*/
        welcomeBinding.timeWe.setOnClickListener(v -> {
            timer.purge();
            timer.cancel();
            String splash = SharedPreferencesUtils.getString(Constants.SPLASH, "");
            if (TextUtils.isEmpty(splash)) {
                startActivity(new Intent(HZKLAdActivity.this, HZKLSplashActivity.class));
                finish();
                return;
            }
            /*String user = SharedPreferencesUtils.getString(Constants.SP_USER_TOKEN, null);
            Timber.i("user=%s", user);
            if (TextUtils.isEmpty(user)) {
                startActivity(new Intent(HZKLAdActivity.this, HZKLLoginActivity.class));
            } else {
                startActivity(new Intent(HZKLAdActivity.this, MainActivity.class));
            }*/
            startActivity(new Intent(HZKLAdActivity.this, MainActivity.class));
            finish();
        });

    }

}
